<template>
  <div class="waybillEdit">
    <!-- class="tab-container waybill-tab-container tab-fixed" -->
    <!-- <el-button @click="toPage">toPage</el-button> -->

    <div style="position: fixed;z-index: 11; top: 10px; left: 70px;">
      <span style="font-size:16px;">{{ Constatvariable.waybillNo }} </span>
      <el-tooltip effect="light" content="点击复制" placement="bottom">
        <i
          class="el-icon-copy-document tag-read"
          :data-clipboard-text="Constatvariable.waybillNo"
          @click="copy"
        ></i>
      </el-tooltip>

      <!-- <div slot="content" style="height:40px;width:200px;"> -->
      <div
        style="width:70px;position: fixed;z-index: 11; top: 10px; left: 190px;"
      >
        <el-popover trigger="hover" placement="bottom">
          <span
            v-if="
              Constatvariable.trackNumber != null &&
                Constatvariable.trackNumber != 'null'
            "
          >
            {{ Constatvariable.trackNumber }}
          </span>
          &nbsp;
          <span
            v-if="
              Constatvariable.track1Type != null &&
                Constatvariable.track1Type != 'null'
            "
          >
            {{ Constatvariable.track1Type }}
          </span>

          <span
            v-if="
              Constatvariable.trackNumber2 != null &&
                Constatvariable.trackNumber2 != 'null'
            "
            >{{ Constatvariable.trackNumber2 }}</span
          >
          &nbsp;
          <span
            v-if="
              Constatvariable.track2Type != null &&
                Constatvariable.track2Type != 'null'
            "
          >
            {{ Constatvariable.track2Type }}</span
          >

          <span
            v-if="
              Constatvariable.trackNumber3 != null &&
                Constatvariable.trackNumber3 != 'null'
            "
          >
            {{ Constatvariable.trackNumber3 }}</span
          >
          &nbsp;
          <span
            v-if="
              Constatvariable.track3Type != null &&
                Constatvariable.track3Type != 'null'
            "
            >{{ Constatvariable.track3Type }}</span
          >
          <div
            slot="reference"
            v-if="Constatvariable.trackNumber !== null"
            class="text-cut"
          >
            {{ Constatvariable.trackNumber }}
          </div>
        </el-popover>
      </div>

      <!-- </div> -->
      <!-- <span style="color:red"> 追踪号</span>-->

      <span
        v-if="
          null != Constatvariable.waybillMergeNo &&
            Constatvariable.waybillMergeNo != ''
        "
        style="font-size:16px;position: fixed;z-index: 11; top: 40px; left: 70px;"
        >合单号:
        <span class="text-blue pointer" @click="toMergeAllEdit">{{
          Constatvariable.waybillMergeNo
        }}</span>
        <el-tooltip effect="light" content="点击复制" placement="bottom">
          <i
            class="el-icon-copy-document tag-read"
            :data-clipboard-text="Constatvariable.waybillMergeNo"
            @click="copyWaybillMergeNo"
          ></i>
        </el-tooltip>
      </span>
    </div>
    <div
      class="flex text-sm align-center"
      style="position: fixed;z-index: 11; top: 70px; left: 70px;width:90%"
    >
      <div class="flex-twice text-cut">
        <span>状态：</span>
        <span class="text-red" v-if="showWaybillDetails">{{
          m(initOptionsData[`waybillStatusMap`][Constatvariable.status])
        }}</span>
        <span class="text-red" v-if="Constatvariable.isDel == true">
          (已删除)
        </span>
      </div>
      <div class="flex-sub text-cut">
        <span>渠道：</span>
        <el-tooltip
          v-if="
            initOptionsData &&
              initOptionsData.channelMap &&
              initOptionsData[`channelMap`][Constatvariable.inStockChannel]
          "
          effect="light"
          placement="bottom"
          :content="
            initOptionsData[`channelMap`][Constatvariable.inStockChannel]
          "
        >
          <span v-if="showWaybillDetails">
            {{
              initOptionsData["channelMap"][Constatvariable.inStockChannel]
            }}</span
          >
        </el-tooltip>
      </div>

      <div class="flex-sub  text-cut">
        <span>目的国家：</span>
        <span v-if="showWaybillDetails">{{
          initOptionsData["countryMap"][Constatvariable.countryId]
        }}</span>
      </div>

      <div class="flex-sub  text-cut">
        <span>国内分区：</span>
        <span v-if="showWaybillDetails">{{
          provinceNameAndIdMap[Constatvariable.provinceId]
        }}</span>
      </div>
      <div class="flex-sub  text-cut">
        <span>实重：</span>
        <span>{{ Constatvariable.inStockActualWeight }}</span>
      </div>
      <div class="flex-sub  text-cut">
        <span>体积(CBM)：</span>
        <span>{{ Constatvariable.inStockVolume }}</span>
      </div>

      <div class="flex-sub  text-cut">
        <span>计费重：</span>
        <span>{{ Constatvariable.inStockChargedWeight }}</span>
      </div>
      <div class="flex-sub  text-cut">
        <span>件数：</span>
        <span>{{ Constatvariable.inStockTotalPackages }}</span>
      </div>
      <div class="flex-sub  text-cut">
        <span>是否包税：</span>
        <span>{{ yesNoOptions[Constatvariable.isTaxFarming] }}</span>
      </div>
      <div class="flex-sub  text-cut">
        <span>是否报关：</span>
        <span>{{ yesNoOptions[Constatvariable.isCustomerDeclaration] }}</span>
      </div>
      <div class="flex-sub  text-cut">
        <span>起运港：</span>
        <span> {{ configPortMap[Constatvariable.shipmentPort] }}</span>
      </div>
      <div class="flex-sub  text-cut">
        <span>中转港：</span>
        <span> {{ configPortMap[Constatvariable.transferPort] }}</span>
      </div>
      <div class="flex-sub  text-cut">
        <span>目的港：</span>
        <span>{{ configPortMap[Constatvariable.destinationPort] }}</span>
      </div>
      <div  v-if="Constatvariable.shippingWay == 'ZX'" class="flex align-center">
        <span>订舱补料：</span>
        <span  v-if="
              this.Constatvariable['bookingSpaceUser'] == '' ||
                this.Constatvariable['bookingSpaceUser'] == null ">
          <img :src ="fileReadPng"/>
      </span>
        <span v-else>
           {{ this.userOptions[this.Constatvariable.bookingSpaceUser] }}
          </span>
      </div>
      <div  v-if="Constatvariable.shippingWay == 'ZX'" class="flex align-center">
        <span>清关文件：</span>
        <span  v-if="
              this.Constatvariable['customsClearanceUser'] == '' ||
                this.Constatvariable['customsClearanceUser'] == null ">
          <img :src ="fileReadPng"/>
      </span>
        <span v-else>
   {{ this.userOptions[this.Constatvariable.customsClearanceUser] }}
          </span>
      </div>
      <div v-if="Constatvariable.shippingWay == 'ZX'" class="flex align-center">
        <span>后端跟进：</span>
        <span  v-if="
              this.Constatvariable['backEndFollowUser'] == '' ||
                this.Constatvariable['backEndFollowUser'] == null ">
          <img :src ="fileReadPng"/>
      </span>
        <span v-else>
  {{ this.userOptions[this.Constatvariable.backEndFollowUser] }}
          </span>
      </div>
      <div  v-if="Constatvariable.shippingWay == 'ZX'" class="flex align-center">
        <span>后端派送：</span>
        <span  v-if="
              Constatvariable.backEndDeliveryUser == '' ||
                 Constatvariable.backEndDeliveryUser == null ">
          <img :src ="fileReadPng"/>
      </span>
        <span v-else-if="Constatvariable.trackNumber==null || Constatvariable.trackNumber==''">
     {{ this.userOptions[this.Constatvariable.backEndDeliveryUser] }}
          </span>
      </div>
    </div>
    <div
      style="position: fixed;z-index: 11; top: 10px; left: 270px;"
      v-if="showWaybillDetails"
    >
      <HeaderInfo
        :Constatvariable="Constatvariable"
        :initOptionsData="initOptionsData"
        :verifyShow.sync="verifyShow"
        :pageType.sync="pageType"
        @editWaybillInfo='editWaybillInfo'
      ></HeaderInfo>
    </div>
    <!-- <el-card> -->

    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane
        label="运单详情"
        name="edit"
        class="tabPane"
        v-if="verifyShow.waybillView"
      >
        <keep-alive>
          <div class="padding-tb">
            <!-- 物流轨迹 -->
            <ProgressBar
              class="progressBar"
              ref="bar"
              :progressList="progress"
              @saveStateLine="saveStateLine"
              @addFlowNodeAnomaly="addFlowNodeAnomaly"
              @flashWaybillInfo="initWaybillData"
              @fixAnomalyNode="fixAnomalyNode"
              :waybillInfo="Constatvariable"
              :shippingWay="Constatvariable.shippingWay"
              :allFlowNodeAnomalyMap="allFlowNodeAnomalyMap"
              :waybillAnomalyNodeMap="waybillAnomalyNodeMap"
              :waybillAnomalyNodeIdsMap="waybillAnomalyNodeIdsMap"
              :flowNodeAnomalyMap="flowNodeAnomalyMap"
              :userMap="userMap"
            ></ProgressBar>
            <el-collapse
              v-model="activeNames"
              class="margin-bottom"
              @change="changeInvoice"
            >
              <el-collapse-item
                name="WaybillDetails"
                class="margin-bottom"
                v-if="verifyShow.waybInfo"
              >
                <template slot="title">
                  <el-row style="width:100%" class="padding-lr">
                    <el-col :span="4">
                      <!-- <span class="fa fa-clipboard-list text-lg"></span> -->
                      <i class="el-icon-notebook-2 text-lg"></i>
                      <span class="text-df text-bold margin-left-sm"
                        >运单信息</span
                      >
                    </el-col>
                  </el-row>
                </template>

                <AirWaybillDetails
                  :verifyShow="verifyShow"
                  :Constatvariable="Constatvariable"
                  :initOptionsData="initOptionsData"
                  :provinceNameAndIdMap="provinceNameAndIdMap"
                  @initWaybillData="initWaybillData"
                  v-if="
                    showWaybillDetails && Constatvariable.shippingWay === 'AIR'
                  "
                ></AirWaybillDetails>
                <WaybillDetails
                ref="WaybillDetails"
                  :verifyShow="verifyShow"
                  :Constatvariable="Constatvariable"
                  :initOptionsData="initOptionsData"
                  :provinceNameAndIdMap="provinceNameAndIdMap"
                  @initWaybillData="initWaybillData"
                  v-if="
                    showWaybillDetails && Constatvariable.shippingWay != 'AIR'
                  "
                ></WaybillDetails>
              </el-collapse-item>
              <el-collapse-item
                name="PickUpOrderInfo"
                class="margin-bottom"
                v-if="verifyShow.pickUpView"
              >
                <template slot="title">
                  <el-row style="width:100%" class="padding-lr">
                    <el-col :span="4">
                      <!-- <span class="fa fa-clipboard-check text-lg"></span> -->

                      <i class="el-icon-tickets text-lg"></i>

                      <span class="text-df text-bold margin-left-sm"
                        >提单信息</span
                      >
                    </el-col>
                    <el-col :span="20">
                      <div class="flex">
                        <span class="flex-sub  text-cut"
                          >起运港：<span v-if="showWaybillDetails">
                            {{ configPortMap[Constatvariable.shipmentPort] }}
                          </span></span
                        >
                        <span class="flex-sub  text-cut"
                          >目的港：<span v-if="showWaybillDetails">
                            {{ configPortMap[Constatvariable.destinationPort] }}
                          </span></span
                        >
                        <span
                          v-if="
                            pageType == 'airFreight' &&
                              ((!verifyShow.saler &&
                                !verifyShow.saleAssistant) ||
                                verifyShow.superAdmin)
                          "
                          class="flex-sub  text-cut"
                          >航空公司：<span v-if="showWaybillDetails">
                            {{
                              initOptionsData["airlineMap"][
                                Constatvariable.shipOrAirlineCompany
                              ]
                            }}
                          </span></span
                        >
                        <span
                          v-if="
                            pageType == 'airFreight' &&
                              (!verifyShow.saler || verifyShow.superAdmin)
                          "
                          class="flex-sub  text-cut"
                          >M单号：<span v-if="showWaybillDetails">
                            {{ Constatvariable.masterNumber }}
                          </span></span
                        >
                        <span
                          class="flex-sub  text-cut"
                          v-if="
                            (!verifyShow.saler && !verifyShow.saleAssistant) ||
                              verifyShow.superAdmin
                          "
                          >订舱服务商：<span v-if="showWaybillDetails">
                            {{
                              initOptionsData["serviceCompanyMap"][
                                Constatvariable.serviceCompanyId
                              ]
                            }}
                          </span></span
                        >
                      </div>
                    </el-col>
                  </el-row>
                </template>

                <AirPickUpOrderInfo
                  v-if="showHMdata && Constatvariable.shippingWay == 'AIR'"
                  :verifyShow="verifyShow"
                  :Constatvariable="Constatvariable"
                  :pageType="pageType"
                ></AirPickUpOrderInfo>
                <PickUpOrderInfo
                  v-if="showHMdata && Constatvariable.shippingWay != 'AIR'"
                  :verifyShow="verifyShow"
                  :Constatvariable="Constatvariable"
                  :pageType="pageType"
                ></PickUpOrderInfo>
              </el-collapse-item>
              <!--  -->
              <el-collapse-item
                class="margin-bottom"
                name="ContainerInfo"
                v-if="containerShow"
              >
                <template slot="title">
                  <el-row style="width:100%" class="padding-lr">
                    <el-col>
                      <i class="el-icon-truck text-lg"></i>
                      <span class="text-df text-bold margin-left-sm"
                        >柜子信息</span
                      >
                    </el-col>
                  </el-row>
                </template>
                <ContainerInfo
                  :Constatvariable="Constatvariable"
                  :pageType="pageType"
                ></ContainerInfo>
              </el-collapse-item>
              <el-collapse-item
                class="margin-bottom"
                name="Invoice"
                v-if="
                  verifyShow.invoiceView && Constatvariable.shippingWay != 'AIR'
                "
              >
                <template slot="title">
                  <el-row style="width:100%" class="padding-lr">
                    <i class="el-icon-copy-document text-lg"></i>
                    <span class="text-df text-bold margin-left-sm"
                      >箱单发票</span
                    >
                    <el-button
                      style="margin-left:500px;"
                      type="text"
                      v-if="
                        verifyShow.invoiceViewEdit &&
                          Constatvariable.orderLocked != 1
                      "
                      @click="editInvoiceBox"
                      >编辑</el-button
                    >
                  </el-row>
                </template>
                <Invoice
                  :country="countryName"
                  :Constatvariable.sync="Constatvariable"
                ></Invoice>
              </el-collapse-item>
            </el-collapse>

            <Ams
                v-if="Constatvariable.shippingway == 'FCL'"
                :waybillData="Constatvariable"
                :restaurants="restaurants"
              >
              </Ams>

              <Isf :restaurants="restaurants" :waybillData="Constatvariable" v-if="
                    Constatvariable.shippingway == 'FCL'
                "></Isf>
          </div>
        </keep-alive>
      </el-tab-pane>
      <el-tab-pane
        label="文件列表"
        name="fileList"
        lazy
        v-if="verifyShow.fileView"
      >
        <FileList
          :verifyShow="verifyShow"
          :Constatvariable="Constatvariable"
          :isAllocat="false"
        ></FileList>
      </el-tab-pane>
      <el-tab-pane
        label="应收应付/阿米巴"
        name="receviePay"
        lazy
        v-if="verifyShow.payAndReceView || verifyShow.amoebaView"
      >
        <Receivable
          v-if="verifyShow.payAndReceView"
          ref="rec"
          :verifyShow="verifyShow"
          :Constatvariable="Constatvariable"
          :initOptionsData="initOptionsData"
        ></Receivable>
        <Amoeba
          v-if="verifyShow.amoebaView"
          :Constatvariable="Constatvariable"
          :verifyShow="verifyShow"
          :initOptionsData="initOptionsData"
          @updateToReceive="updateReceive"
        ></Amoeba>
      </el-tab-pane>
    </el-tabs>
    <!-- </el-card> -->
    <div
      style="width:70px;position: fixed;z-index: 11; top: 10px; left: 190px;"
    >
    </div>
  </div>
</template>
<script>
import { m } from "@/store/yg/common/local";
import { ajax } from "@/store/yg/common/utils";
import fileReadPng from "@/assets/images/file-read.png";
import Clipboard from "clipboard";
const HeaderInfo = () => import("./components/HeaderInfo");
const ContainerInfo = () => import("./components/ContainerInfo");
const Invoice = () => import("./components/Invoice");
const PickUpOrderInfo = () => import("./components/PickUpOrderInfo");
const AirPickUpOrderInfo = () => import("./components/AirPickUpOrderInfo");
const ProgressBar = () => import("@/components/app/components/ProgressBar");
const Receivable = () => import("./components/Receivable");
const WaybillDetails = () => import("./components/WaybillDetails");
const AirWaybillDetails = () => import("./components/AirWaybillDetails");

const Amoeba = () => import("./components/Amoeba");
const FileList = () => import("./components/FileList");
const Ams = () => import("../waybillmerge/components/AMS.vue");
const Isf = () => import("../waybillmerge/components/ISF.vue");

// import headerInfo from "./components/headerInfo";
export default {
  components: {
    HeaderInfo,
    ContainerInfo,
    Invoice,
    PickUpOrderInfo,
    AirPickUpOrderInfo,
    ProgressBar,
    Receivable,
    WaybillDetails,
    AirWaybillDetails,
    Amoeba,
    FileList,
    Ams,
    Isf
  },
  props: [],
  data() {
    return {
      pageType: "airFreight",
      isEdit: true,
      fileReadPng:fileReadPng,
      progress: [],
      allFlowNodeAnomalyMap: {},
      waybillAnomalyNodeMap: {},
      waybillAnomalyNodeIdsMap: {},
      flowNodeAnomalyMap: {},
      userMap: {},
      userOptions:[],
      waybillInfo: {},
      containerShow: false,
      showWaybillDetails: false,
      activeName: "edit",
      provinceNameAndIdMap: {},
      verifyShow: {},
      activeNames: [
        "WaybillDetails",
        "Invoice",
        "PickUpOrderInfo",
        "Receivable",
        "FileList",
        "Amoeba",
        "ContainerInfo"
      ],
      showInvoice: false,
      headData: {
        search: ""
      },
      rules: {
        search: []
      },
      // isEdit: true,//是否允许编辑
      // progress: [],//点击轨迹节点请求返回的数据
      waybillTimerShaft: {
        waybillId: ""
      },
      //港口信息 海运和空运不一样
      configPortMap: {},
      Constatvariable: {},
      //下拉 值
      initOptionsData: {},
      restaurants: {},
      showHMdata: false,
      yesNoOptions: {
        1: "是",
        0: "否"
      },

    };
  },
  computed: {
    countryName() {
      if (!this.initOptionsData.countryMap) return;
      if (!this.Constatvariable.countryId) return;

      return this.initOptionsData.countryMap[this.Constatvariable.countryId];
    }
  },
  watch: {},
  created() {},
  mounted() {
    this.initWaybillData();
    this.initOptions();
    this.init();
    let tabName = sessionStorage.getItem("waybillAllTab");
    //判断是否存在currentTab,即tab页之前是否被点击切换到别的页面
    if (tabName) {
      this.activeName = tabName;
    }
  },
  destroyed() {
    sessionStorage.removeItem("waybillAllTab");
  },
  methods: {

    toMergeAllEdit() {
      //获取当前路由地址
      const urlPath = this.$route.path;
      const waybillId = this.Constatvariable["waybillMergeId"];
      if (
        this.Constatvariable.shippingWay == "LCL" ||
        this.Constatvariable.shippingWay == "FCL"
      ) {
        var url = "#/blank/waybill__seafreightmerge__main";

        url = url + "?shippingway=0&waybillId=" + waybillId;
        window.open(url, "_blank");
      } else if (
        this.Constatvariable.shippingWay == "AIR" ||
        this.Constatvariable.shippingWay == "ZX"
      ) {
        var url = "#/blank/waybill__airfreightmerge__main";
        url = url + "?shippingway=1&waybillId=" + waybillId;
        window.open(url, "_blank");
      }
    },

    updateReceive() {
      if (this.$refs.rec) {
        this.$refs.rec.lazyloadWaybillReceivePayables();
      }
    },
    handleClick(tab) {
      // 点击tab后触发事件，修改显示页面
      sessionStorage.setItem("waybillAllTab", tab.name);
    },
    async saveStateLine(params) {
      //保存轨迹节点
      console.log("params", params);
      console.log("Constatvariable", this.Constatvariable);
      params.waybillId = this.Constatvariable.id;
      params.time = params.operationDateTime;
      params.clickStatus = params.status;
      console.log("params2", params);
      const data = await ajax("updateWaybillStateAndTime", params);

      if (data.code === 200) {
        this.initWaybillData();
      } else {
        this.$message.error(data.failTips);
      }
    },

    async addFlowNodeAnomaly(params){
      console.log("params", params);
      const data = await ajax("addFlowNodeAnomaly", params);
      if (data.code === 200) {
        this.initWaybillData();
      } else {
        if(data.message) {
          this.$message.error(data.message);
        }
      }
    },
    async fixAnomalyNode(id){
      const data = await ajax("fixAnomalyNode", {id:id});
      if (data.code === 200) {
        this.$message.success("提交解决成功");
        this.initWaybillData();
      } else {
        this.$message.error("提交解决失败");
      }
    },
    initOptions(){
      var param = {};
      ajax("getUserOptions", param).then(
        res => {
          if (res.code === 200) {
            this.userOptions=res.data;
            console.log("返回数据:",this.userOptions)
          } else {
            this.$message.error("操作失败!");
          }
        },
        error => {
          console.log(error);
        }
      );

    },
    // 初始化 运单数据
    initWaybillData() {
      var param = {};
      param["type"] = 1;
      ajax("verifyPermissions", param).then(
        res => {
          this.verifyShow = res;
        },
        error => {
          console.log(error);
        }
      );
      //直接从缓存获取
      const waybillId = this.$route.query.waybillId;
      const waybillNo = this.$route.query.waybillNo;
      const content = this.$route.query.content;
      param["id"] = waybillId;
      param["waybillNo"] = waybillNo;
      ajax("getWaybillInfo", param).then(
        res => {
          if (res.code == 200) {
            this.Constatvariable = res.data;
            this.Constatvariable.netAddress  = res.data2["netAddress"];
            this.waybillAnomalyNodeMap= res.data2["waybillAnomalyNodeMap"];
            this.waybillAnomalyNodeIdsMap= res.data2["waybillAnomalyNodeIdsMap"];
            this.flowNodeAnomalyMap= res.data2["flowNodeAnomalyMap"];
            this.userMap = res.data2["userMap"];
            document.title = this.Constatvariable.waybillNo;
            this.queryFbaCodeByCoutry({
              id: this.Constatvariable.countryId,
              param1: this.Constatvariable.purposeWarehouseType
            });
            this.$router.push({
              query: {
                waybillNo: waybillNo,
                content: content,
                waybillId: res.data["id"],
                shippingway: res.data["shippingway"]
              }
            });
            this.showHMdata = true;
            var shippingway = res.data["shippingWay"];
            if (
              shippingway == "LCL" ||
              shippingway == "FCL" ||
              shippingway == "LCLG" ||
              shippingway == "FCLG"
            ) {
              this.pageType = "seaFreight";
            }

            if(shippingway == "FCL") {
              this.getOptionsByparam()
            }
            console.log("当前物流渠道", shippingway);
            // 只有海运才有柜子
            if (
              shippingway &&
              (shippingway == "FCL" ||
                shippingway == "LCL" ||
                shippingway == "LCLG" ||
                shippingway == "FCLG")
            ) {
              this.containerShow = true;
            }
            var channelCapacity = res.data["channelCapacity"];
            if (channelCapacity) {
              var abilitys = channelCapacity.split(",");
              console.log("渠道能力", abilitys);
              this.Constatvariable["abilitys"] = abilitys;
            }

            var specialProduct = res.data["specialProduct"];
            if (specialProduct) {
              var specialProducts = specialProduct.split(",");
              console.log("渠道能力", specialProducts);
              this.Constatvariable["specialProducts"] = specialProducts;
            }
          } else {
            this.$message.error(res.message);
            if (res.message) {
              if (res.message.indexOf("权限") > -1) {
                window.open("/", "_self");
              }
            }
          }
        },
        error => {
          console.log(error);
        }
      );
    },
    async queryFbaCodeByCoutry(param) {
      const data = await ajax("queryFbaCodeByCoutry", param);
      if (data.code !== 200) {
        if (null != data.message) {
          this.$message.error(m(data.message));
        } else {
          // this.$message.error("获取国家失败!");
        }
        return;
      }

      const addressList = data.data["shippingFbaStocks"];

      const cf = this.Constatvariable;
      let zipCode = "";
      const fbaStockCode =
        cf.purposeWarehouseType === 700 ? "" : cf.dispatchAddressCode;
      if (fbaStockCode) {
        const t = addressList.find(x => x.fbaCode === cf.dispatchAddressCode);
        zipCode = t ? t.zipCode : "";
      } else {
        zipCode = cf.dispatchZipCode;
      }
      const params = {
        channelLoadingPortId: parseInt(cf.loadingPort), //  起运地
        countryId: parseInt(cf.countryId), //  目的国家
        weight: parseFloat(cf.customerActualWeight), //  重量
        volumn: parseFloat(cf.customerVolume), //  体积
        channelAbility: cf.channelCapacity.toString(), //  渠道能力
        specialProduct: cf.specialProduct.toString(), //  特殊产品
        other: `${cf.deliveryTerms === "DDP" ? 29 : 28},${
          cf.isTaxFarming ? 32 : 38
        }`, //  其他属性
        type: 1, //  客户渠道查询：0代表查询，1代表下单
        shipingWay: cf.shippingWay,
        customerId: cf.customerId,
        fbaStockCode: fbaStockCode,
        zipCode: zipCode
      };

      const res = await ajax("queryInStockChannel", params);
      if (res.code != 200) {
        if (null != res.message) {
          this.$message.error(m(res.message));
        }
        return;
      }

      const customerChannelFormMap = res.data.customerChannelFormMap; //  渠道列表
      // const provinceNameAndIdMap = []; //  渠道信息列表
      if (customerChannelFormMap) {
        console.log("customerChannelFormMap :>> ", customerChannelFormMap);
        const map =
          customerChannelFormMap[cf.inStockChannel].provinceNameAndIdMap;
        const p = {};
        for (const i in map) {
          p[map[i]] = i;
        }
        this.provinceNameAndIdMap = p;
      }
    },
    editInvoiceBox() {
      const url = "#/blank/waybill__allmergeedit__main";
      const id = this.$route.query.waybillId;
      let isJapan = 0;

      if (
        this.countryName &&
        this.countryName != "undefined" &&
        this.countryName.indexOf("日本") !== -1
      ) {
        isJapan = 1;
      }
      // this.$store.dispatch("loadBlankEntry", url);
      window.open(`${url}?waybillId=${id}&isJapan=${isJapan}`, "_blank");
      // location.href = url + "?waybillId=" + this.data["id"];
    },
    async init() {
      // this.getProgress(); //轨迹条初始化
      var param = {};
      param["id"] = this.$route.query.waybillId;
      param["param1"] = this.$route.query.waybillNo;
      const initData = await ajax("getAllOptions", param);
      if (initData.data) {
        if (!initData.data["countryStateMap"]) {
          initData.data["countryStateMap"] = {};
        }
        this.initOptionsData = initData.data;
        if (this.pageType == "seaFreight") {
          this.configPortMap = this.initOptionsData.configPortMap;
        } else {
          this.configPortMap = this.initOptionsData.airPortMap;
        }
        this.showWaybillDetails = true;
        this.allFlowNodeAnomalyMap = initData.data["allFlowNodeAnomalyMap"];
      } else {
        console.log("查询下拉接口出错 请检查接口");
      }


    },
    getOptionsByparam() {
      ajax("getOptionsByparam", { type: "shippingParty" }).then(
        res => {
          console.log("获取申报信息" + res.data);
          if (res.code != 200) {
            this.$message.error(res.message);
          } else {
            if (null != res.data) {
              this.restaurants = res.data;
            }
          }
        },
        error => {
          console.log(error);
        }
      )
    },
    m(k) {
      return m(k);
    },
    submitForm() {
      this.$refs["boxForm"].validate(valid => {
        if (!valid) return;
        // TODO 提交表单
      });
    },
    resetForm() {
      this.$refs["boxForm"].resetFields();
    },
    changeInvoice(val) {
      console.log(
        "%cval: ",
        "color: MidnightBlue; background: Aquamarine;",
        val
      );
      // this.showInvoice = !this.showInvoice;
    },
    // toPage() {

    //   window.open("#/blank/waybill__airFreightList__main", "_blank");
    // }
    copy() {
      var clipboard = new Clipboard(".tag-read");
      clipboard.on("success", e => {
        this.$message.success("复制成功");
        // 释放内存
        clipboard.destroy();
      });
      clipboard.on("error", e => {
        // 不支持复制
        this.$message.error("该浏览器不支持自动复制");
        // 释放内存
        clipboard.destroy();
      });
    },
    // 复制合单号
    copyWaybillMergeNo() {
      var clipboard = new Clipboard(".tag-read");
      clipboard.on("success", e => {
        this.$message.success("复制成功");
        // 释放内存
        clipboard.destroy();
      });
      clipboard.on("error", e => {
        // 不支持复制
        this.$message.error("该浏览器不支持自动复制");
        // 释放内存
        clipboard.destroy();
      });
    },
    editWaybillInfo() {
      console.log('改变事件 :>> ');
      this.$refs.WaybillDetails.changeForecastInfo(1)
    }
  }
};
</script>
<style scoped>
.row-item >>> .el-col {
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
/deep/ .el-form-item__content {
  font-size: 12px;
}

/deep/ .el-autocomplete {
  width: 100%;
}
</style>

<style lang="scss">
.row-item {
  color: #3f4652;
  line-height: 28px;
  margin-bottom: 14px;
  font-size: 12px;
}
</style>
<style>
.waybillEdit .el-tabs {
  padding-top: 40px;
}
.waybillEdit .el-tabs__header {
  position: fixed;
  top: 64px;
  z-index: 8;
  background: #fff;
  width: 100%;
  left: 60px;
  padding-top: 20px;
}

/* .tabPane .progressBar {
  position: fixed;
  top: 124px;
  z-index: 10;
  width: 90%;
} */
</style>
